<?php

/**
 * This is the model class for table "public.site".
 *
 * The followings are the available columns in table 'public.site':
 * @property string $id
 * @property string $name
 * @property boolean $status
 * @property boolean $default
 * @property string $creation_datetime
 * @property string $last_update
 * @property string $table_prefix
 *
 * The followings are the available model relations:
 * @property SiteUrl[] $siteUrls
 * @property Workflow[] $workflows
 * @property Page[] $pages
 */
class SiteBase extends CActiveRecord
{
    /**
     * Returns the static model of the specified AR class.
     * @return Site the static model class
     */
    public static function model($className = 'Site')
    {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName()
    {
        return SITE_TABLE_PREFIX . 'site';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        return array(
            array('name', 'required'),
            array('name', 'length', 'max' => 100),
            array('status, default, creation_datetime, last_update, locale_id', 'safe'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('id, name, status, default, creation_datetime, last_update', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations()
    {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
            'siteUrls' => array(self::HAS_MANY, 'SiteUrl', 'site_id'),
            'workflows' => array(self::HAS_MANY, 'Workflow', 'site_id'),
            'pages' => array(self::HAS_MANY, 'Page', 'site_id'),
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'id' => 'ID',
            'name' => 'Name',
            'status' => 'Status',
            'default' => 'Default',
            'creation_datetime' => 'Creation Datetime',
            'last_update' => 'Last Update',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search()
    {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('id', $this->id, true);
        $criteria->compare('name', $this->name, true);
        $criteria->compare('status', $this->status);
        $criteria->compare('default', $this->default);
        $criteria->compare('creation_datetime', $this->creation_datetime, true);
        $criteria->compare('last_update', $this->last_update, true);

        return new CActiveDataProvider(get_class($this), array(
            'criteria' => $criteria,
        ));
    }
}